package com.banzhi.shop.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.banzhi.shop.R;

import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.data.ADImagesBean;
import com.banzhi.shop.data.BeCityPartnersData;
import com.banzhi.shop.model.CallBack.BeCityPartnersCallBack;
import com.banzhi.shop.model.Impl.BeCityPartnersImpl;
import com.banzhi.shop.state.URLString;
import com.banzhi.shop.utils.LogUtils;
import com.banzhi.shop.utils.NoTokenUtils;
import com.banzhi.shop.utils.ToastUtils;
import com.banzhi.shop.utils.Translucent;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import org.json.JSONObject;

//城市合伙人申请
public class ApplicationActivity extends BaseActivity implements View.OnClickListener, BeCityPartnersCallBack {

    private ImageView mIvBackApplication;
    private ImageView mIvPartnerApplication;
    private BeCityPartnersData mPartnersData;
    private String mCheck;
    private String mIspay;
    private String mCode;
    private BeCityPartnersImpl mModel;
    private JSONObject mJsonObject;
    private TextView mTvApplication;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_application);
        Translucent.setTranslucent(this);
        mModel = new BeCityPartnersImpl();
        mModel.beCityPartners(this);

        initView();
        initData();
    }

    //初始化界面
    private void initView() {
        mIvBackApplication = (ImageView) findViewById(R.id.iv_back_application);
        mIvPartnerApplication = (ImageView) findViewById(R.id.iv_partner_application);
        mTvApplication = (TextView) findViewById(R.id.tv_applicaction);
        Glide.with(this).load(URLString.CityPartnerPicURL).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(mIvPartnerApplication);
    }

    //设置点击事件
    private void initData() {
        mIvBackApplication.setOnClickListener(this);
        mIvPartnerApplication.setOnClickListener(this);
        mTvApplication.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back_application:
                finish();
                break;

            case R.id.tv_applicaction:
                // mModel.beCityPartners(this);

                 /*  "check":0, //0 待审核 1 审核通过 2 审核拒绝 3 未提交资料
                    "ispay":0, //0未支付  1已支付*/
                // startActivity(new Intent(ApplicationActivity.this, MyShoperActivity.class));
                if ("0".equals(mCode)) {
                    if ("3".equals(mCheck)) {
                        Intent intent = new Intent(ApplicationActivity.this, PartnerApplicationActivity.class);
                        startActivity(intent);

                    } else if ("0".equals(mCheck) && "0".equals(mIspay)) {//进入支付界面
                        Intent intent = new Intent(this, PartnerCheckstandActivity.class);
                        ToastUtils.makeToastShort("申请信息已提交，请支付合伙人的费用");
                        startActivity(intent);

                    } else if ("2".equals(mCheck) && "1".equals(mIspay)) {//进入修改
                        Intent intent = new Intent(ApplicationActivity.this, AuditStateFailActivity.class);
                        intent.putExtra("mCheck", "2");
                        intent.putExtra("mIspay", "1");
                        startActivity(intent);

                    } else if ("0".equals(mCheck) && "1".equals(mIspay)) {//审核中
                        Intent intent = new Intent(this, AuditStateActivity.class);
                        startActivity(intent);
                    } else if ("1".equals(mCheck)) {
                        Intent intent = new Intent(this, CityPartnerActivity.class);
                        startActivity(intent);
                    }
                } else {
                    ToastUtils.makeToastShort(mJsonObject.optString("msg"));
                }
                break;
        }

    }

    @Override
    public void beCityPartnersSuccess(Object object) {
        mPartnersData = (BeCityPartnersData) object;
        ShowViews();


    }

    private void ShowViews() {
        mCode = mPartnersData.getCode();
        mCheck = mPartnersData.getCheck();
        mIspay = mPartnersData.getIspay();

    }

    @Override
    public void beCityPartnersError(Object object) {
        mJsonObject = (JSONObject) object;
        NoTokenUtils.loginOut(this, mJsonObject);
        //    ToastUtils.makeToastShort(jsonObject.optString("msg"));

    }
}
